package za.co.yellowfire.solarflare.web.model;

import za.co.yellowfire.solarflare.annotation.SearchableProperty;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.validation.constraints.Size;
import java.io.Serializable;

/**
 * @author Mark P Ashworth
 * @version 0.0.1
 */
@Embeddable
public class Name implements Serializable {
    private static final long serialVersionUID = 1L;

    @Size(min = 0, max = 45)
    @Column(name = "first_name")
    @SearchableProperty(name = "name")
    private String firstName;

    @Size(min = 0, max = 45)
    @Column(name = "last_name")
    @SearchableProperty
    private String lastName;

    /** Default constructor */
    public Name() { }

    /**
     * Constructs the name
     * @param firstName The first name
     * @param lastName The last name
     */
    public Name(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    /**
     * The first name
     * @return String
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * The first name
     * @param firstName The new first name
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * The last name
     * @return String
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * The last name
     * @param lastName The new last name
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * Returns the first name and last name
     * @return First name + ' ' + Last name
     */
    public String getFullName() {
        return getFirstName() + " " + getLastName();
    }

    /**
     * The object as a JSON string
     * @return String
     */
    @Override
    public String toString() {
        return "Name{" +
                "firstName='" + firstName + '\'' +
                ", lastName='" + lastName + '\'' +
                '}';
    }
}
